<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" %>
<%@page import="connection.DBConnection"%>
<%@page import="java.util.*" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Customer Master Report</title>

<script language="javascript" type="text/javascript">
/*
 function addRowHandlers() {
 var table = document.getElementById("tableId");
 var rows = table.getElementsByTagName("tr");

 for (int i = 0; i < rows.length; i++) {
    var currentRow = table.rows[i];
    currentRow.onclick = createClickHandler(currentRow);
 }
}

function createClickHandler(row){

            return function() { 
                   var cell = row.getElementsByTagName("td")[0];// if you put 0 here then it will return first column of this row
                       var id = cell.innerHTML;
                        alert("id:" + id);
              };

}

addRowHandlers();
*/

function go()
{
	var r = window.confirm("Do you want to edit entry? ");
	if (r = true) 
	{
	    var cell=document.getElementsByTagName("td")[1];
	    var id = cell.innerHTML;
 
	    window.open("CustomerMaster.jsp");	    
	    
	} 
	else 
	{
	    x = "You pressed Cancel!";
	}
}

</script>

</head>
<body>

<form name="fr1" method="post">

   <%
        String exportToExcel = request.getParameter("exportToExcel");
        if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) 
        {
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "inline; filename=" + "CustomerMasterReport.xls");
 
        }
    %>

<h2 align="center"> Customer Master Report</h2>
<table border="1" align="center"> 
<tr>
		<th> Customer Name </th>
		<th> Customer Code </th>
		<th> Address </th>
		<th> City </th>
		<th> State </th>
		<th> TIN Number </th>
		<th> PAN Number </th>
		<th> Mobile number </th>
		<th> Email ID</th>
		<th> Contact Person Name</th>
		<th> Opening Balance </th>	 
</tr>


		<%  DBConnection dbc=new DBConnection();
			Connection con=dbc.getNewConnection();
			Statement st = null;
			ResultSet rs = null;
			
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select * from CustomerMaster where status=1"); %>
	        	
       		 <%  while(rs.next()){ %>
<tr>
			<% String name=rs.getString(1);
				String code=rs.getString(2); %>

            		<td><a href="http://localhost:8081/BOA_Web/EditCustomerMaster.jsp?code1=<%=code%>&name1=<%=name%>"> <%=name %> </a></td>
            		<td> <%=code %></td>
            		<td><%= rs.getString(3)%></td>
            		<td><%= rs.getString(4)%></td>
            		<td><%= rs.getString(5)%></td>
            		<td><%= rs.getString(6)%></td>
            		<td><%= rs.getString(7)%></td>
            		<td><%= rs.getString(8)%></td>
            		<td><%= rs.getString(9)%></td>
            		<td><%= rs.getString(10)%></td>
            		<td><%= rs.getDouble(11)%></td>
</tr>
        		<% } %>
  
	 		<% }
			catch(Exception e){} %>


</table><br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <%
        if (exportToExcel == null) {
    %>
    <a href="CustomerMasterReport.jsp?exportToExcel=YES">Export to Excel</a>
    <%
        }
    %>
</form>
<br> <br>

<form name=deletecustomer action="CustomerMasterDeleteServlet">
<input type="text" name="delete"> 
<input type=submit value="Delete">

<br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="http://localhost:8081/BOA_Web/DeletedCustomerMaster.jsp">Deleted Customer Masters</a>

<center><input type="button" value="Print this page" onClick="window.print()"></center>

</form>

</body>
</html>